#coding=utf-8
'''
Created on 2017-7-10

@author: sandy
'''

import logging

class Prop(object):
    
    def __init__(self):
        self.id = 0
        self.name = u''
        self.icon = u''
        self.price = 0
        

    def parse(self, cfg):
        self.id = cfg.get("id")
        self.name = cfg.get("name")
        self.icon = cfg.get("icon")
        self.price = cfg.get("price")
        logging.debug("id=%d,name=%s,icon=%s price=%s",self.id,self.name,self.icon,self.price)

class PropManager(object):
    
    def __init__(self):
        self.propmap = {}
        
    def onRemoteConfig(self, cfgname, jf):
        if cfgname!= u"centerconfig.prop":
            return
        self.loadFromJson(jf)
            
    def loadFromJson(self, jf):
        logging.info(u"loading centerconfig.prop.json")
        props = jf.get("props")
        for propcfg in props:
            prop = Prop()
            prop.parse(propcfg)
            self.propmap[prop.id] = prop
            
    def getProp(self, propid):
        return self.propmap.get(propid)
    
    def getPropName(self,propid):
        prop = self.getProp(propid)
        if prop:
            return prop.name
    
instance = PropManager()

if __name__ == '__main__':
    pass